<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ajax</title>
</head>
<body>
    <script>
        function ajaxRequest(url,callback){
            let xhr = new XMLHttpRequest();
            xhr.open('GET',url,true);
            xhr.responseType='json'
            xhr.onload = function(){
                callback(null,xhr.response);
            }
            xhr.send();
        }
        //用来存放最终的结果
        let result = [];
        //已经完成的总请求数
        let completedRequests= 0;
        //总请求数 
        let totalRequests = 3;
        function handleResponse(data,index){
            result[index]=data;
            if(++completedRequests === totalRequests){
                console.log(result);
            }
        }
        ajaxRequest('data1.json',function(err,data){
            handleResponse(data,0);
        });
        ajaxRequest('data2.json',function(err,data){
            handleResponse(data,1);
        });
        ajaxRequest('data3.json',function(err,data){
            handleResponse(data,2);
        });

        function requests(urls,callback){

        }
        requests(['data1.json','data2.json','data3.json'],function(err,result){
            console.log(result);
        });
    </script>
</body>
</html>